<?php


namespace Admin\Controller;


use Think\Controller;

class AdminController extends Controller
{
    public function __construct()
    {
        parent::__construct();
        //判断是否登录
        $allow_list = ['Manager-login', 'Manager-loginOut', 'Manager-verify'];
        $url = CONTROLLER_NAME . '-' . ACTION_NAME;
        if (empty(session('name')) && !in_array($url, $allow_list)) {
            $this->error('请先登录', '/index.php/admin/manager/login',2);
            return;
        }
        //判断是否越权访问 无权限页面
        $manager = D('manager')->where('mg_name="'.session('name').'"')->find();
        $role = D('role')->where('role_id=' . $manager['mg_role_id'])->find();
        $auth_ac = $role['role_auth_ac'];
        $allow_list2 = ['Index-index','Index-head','Index-left','Index-right'];
        if (!in_array($url, $allow_list2) && strpos($auth_ac, $url) === false && session('name') !== 'admin') {
            $this->error('权限不足，无法访问','/index.php/admin/index/index');
            return ;
        }
    }
}